

#import "TestUser.h"
#import "AFImageRequestOperation.h"
#import "RequestManager.h"
NSString * const kUserProfileImageDidLoadNotification = @"com.alamofire.user.profile-image.loaded";



@implementation TestUser {
@private
    NSString *_avatarImageURLString;
    AFImageRequestOperation *_avatarImageRequestOperation;
}

@synthesize m_id = _userID;
@synthesize m_username = _username;
@synthesize m_avatar_image;


- (NSURL *)avatarImageURL {
    return [m_avatar_image avatarImageURL];
}
+ (void)getUserWithBlock:(void (^)(NSArray *posts, NSError *error))block {
    [[RequestManager sharedClient] getPath:@"stream/0/posts/stream/global" parameters:nil success:^(AFHTTPRequestOperation *operation, id JSON) {
        
//        NSLog(@"%@",JSON);
        NSMutableArray *mutablePosts = [TestUser arrayOfModelsFromDictionaries:[JSON valueForKeyPath:@"data"]];

        
        if (block) {
            block([NSArray arrayWithArray:mutablePosts], nil);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        if (block) {
            block([NSArray array], error);
        }
    }];
}
+ (void)postUserLogginWithBlock:(TestUser*) user andBlock:(void (^)(NSArray *posts, NSError *error))block {
    
    NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
                            user.m_id, @"userID",
                            @"test", @"password",
                            nil];
    [[RequestManager sharedClient] postPath:@"stream/0/posts/stream/global" parameters:params success:^(AFHTTPRequestOperation *operation, id JSON) {
//        NSLog(@"%@",JSON);
        NSMutableArray *mutablePosts = [TestUser arrayOfModelsFromDictionaries:[JSON valueForKeyPath:@"data"]];
        
        if (block) {
            block([NSArray arrayWithArray:mutablePosts], nil);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        if (block) {
            block([NSArray array], error);
        }
    }];
    
}
@end
